<?php
namespace Home\Controller;
class TransferGoodsController extends AdminController{
	Public function showlist(){
		$db = M('transfer_log');
		$count = $db->count();
		$page = new \Think\Page($count,20);
		$page->rollPage=6;
		$page->lastSuffix =false;
		$page->setConfig('prev', '上一页');
		$page->setConfig('next', '下一页');
		$page->setConfig('first', '首页');
		$page->setConfig('last', '末页');
		$page->setConfig('theme', '共 %TOTAL_ROW% 条记录,当前是 %NOW_PAGE%/%TOTAL_PAGE% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
		$show = $page->show();
		$fields = array(
			'a.id',
			'a.gid',
			'b.g_name',
			'c.name'  => 'from',
			'd.name'  => 'to',
			'a.count',
			'e.dw_name',
			'a.doer',
			'a.d_time'
			);
		$log_l = $db->field($fields)->alias('a')
					->join('top_goods b ON b.g_id = a.gid')
					->join('top_goods_cate c ON c.id = a.from_w')
					->join('top_goods_cate d ON d.id = a.to_w')
					->join('top_goods_dw e ON e.dw_id = b.g_dw_id')
					->order('a.id desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('page',$show);
		$this->assign('log_l',$log_l);
		$this->display();
	}

	Public function transfer(){	
		if(IS_POST){
			$db =D('TransferLog');
			if($db->create()){
				if($db->add()){
					$this->success ('调拨登记成功',U('showlist'));
				}else{
					$this->error ('调拨登记失败');
				}
			}else{
				$this->error ($db->getError());
			}
		}else{
			$cid = I('cid',0,'intval');
			if($cid == 0){
				$this->error('参数传输错误');
			}
			$c_db = M('Goods_cate');
			$c_list = $c_db->select();
			$cate = new \Home\Common\Category;
			$c_list = $cate->unlimitedForLevel($c_list);
			$this->assign('c_list',$c_list);
			$db = M('goods_count') ;
			$g_info = $db->join('LEFT JOIN top_goods ON top_goods_count.gid = top_goods.g_id')
				->join('LEFT JOIN top_goods_cate ON top_goods_cate.id = top_goods_count.bid')
				->join('LEFT JOIN top_goods_dw ON top_goods_dw.dw_id = top_goods.g_dw_id')->find($cid);
			$this->assign('info',$g_info);
			$this->display();
		}
	}

	Public function check(){
		
	}
}